#ifndef FAUDIODECODE_H
#define FAUDIODECODE_H

#include "blockingqueue.h"
#include "QAudioPlayer.h"

#include <QThread>

struct AVCodec;
struct AVCodecContext;
struct AVPacket;
struct AVStream;
struct SwrContext;
class FAudioDecode : public QThread
{
    Q_OBJECT
public:
    explicit FAudioDecode(QObject *parent = nullptr);
    ~FAudioDecode();

    void addAVPacket(AVPacket *packet);
    bool initAVStream(AVStream *pAVStream);

protected:
    void run();

private:
    BlockingQueue<AVPacket *> m_queue;
    BoundedBlockingQueue<AVPacket *> m_queue2 {3};

    AVCodec *m_pAVCodec {nullptr};
    AVCodecContext *m_pAVDecoderCtx {nullptr};
    AVStream *m_pAVStream {nullptr};
    SwrContext *m_swrCtx {nullptr};

    std::unique_ptr<QAudioPlayer> m_audioPlayer;
};

#endif // FAUDIODECODE_H
